package Acwing;

import java.util.Scanner;

public class Acwing4 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int V=sc.nextInt();
        int[] weight=new int[N+1];
        int[] values=new int[N+1];
        int[] nums=new int[N+1];
        int[][] f=new int[N+1][V+1];
        for (int i = 1; i <= N; i++) {
            weight[i]=sc.nextInt();
            values[i]=sc.nextInt();
            nums[i]=sc.nextInt();
        }
        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= V; j++) {
                for(int k=0;k*weight[i]<=j;k++){
                    if(k>nums[i]){
                        break;
                    }
                    f[i][j]=Math.max(f[i][j],f[i-1][j-k*weight[i]]+k*values[i]);
                }
            }
        }
        System.out.println(f[N][V]);
    }
}
